package com.gxuwz.medical.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.gxuwz.medical.domain.family.Family;
import com.gxuwz.medical.domain.family.FamilyMember;
import com.gxuwz.medical.domain.money.Money;
import com.gxuwz.medical.exception.DbException;

public class FamilyMemberDao extends GenericDao<FamilyMember> {

	@Override
	protected FamilyMember handle(ResultSet rs) throws SQLException {
		try{
			FamilyMember familyMember = new FamilyMember();
			familyMember.setCmscode(rs.getString("cmscode"));
			familyMember.setMembercode(rs.getString("membercode"));
			familyMember.setName(rs.getString("name"));
			familyMember.setRelative(rs.getString("relative"));
			familyMember.setFamilycode(rs.getString("familycode"));
			familyMember.setIdcard(rs.getString("idcard"));
			familyMember.setSex(rs.getString("sex"));
			familyMember.setBirthday(rs.getTimestamp("birthday"));
			familyMember.setNation(rs.getString("nation"));
			familyMember.setHealth(rs.getString("health"));
			familyMember.setEducationallevel(rs.getString("educationallevel"));
			familyMember.setMemberattribute(rs.getString("memberattribute"));
			familyMember.setFarmtype(rs.getString("farmtype"));
			familyMember.setMarried(rs.getString("married"));
			familyMember.setWorkunit(rs.getString("workunit"));
			familyMember.setPhone(rs.getString("phone"));
			
			return familyMember;
		}catch(SQLException e){
			
			throw new SQLException("结果集转为实例失败!",e);
		}
	}
	
	public List<FamilyMember> findAll(String familycode)throws DbException{
		try{
			String sql="select * "
					+ "from t_family_member  "
					+ "where familycode=?";
			Object[]params={familycode};
			return super.queryOjects(sql, params);
			}catch(SQLException e){
				
				throw new DbException("根据户主查询家庭成员缴费情况失败",e);
			}
	}
	
	public List<FamilyMember> findAll()throws DbException{
		try{
			String sql="select * "
					+ "from t_family_member";
			Object[]params={};
			return super.queryOjects(sql, params);
			}catch(SQLException e){
				
				throw new DbException("根据户主查询家庭成员缴费情况失败",e);
			}
	}
	
	
	public List<FamilyMember> findByName(String name)throws DbException{
		try{
			String sql="select * "
					+ "from t_family_member  "
					+ "where relative=? and name=?";
			Object[]params={"户主",name};
			return super.queryOjects(sql, params);
			}catch(SQLException e){
				
				throw new DbException("根据户主查询家庭成员缴费情况失败",e);
			}
	}
	
	public List<FamilyMember> findByIdCard(String idCard)throws DbException{
		try{
			String sql="select * "
					+ "from t_family_member  "
					+ "where idcard=?";
			Object[]params={idCard};
			return super.queryOjects(sql, params);
			}catch(SQLException e){
				
				throw new DbException("根据身份证查用户信息失败",e);
			}
	}
}
